package edu.gyc.homework;

public class VIP extends MembershipCard {
    private double overdraft;

    public VIP(int id, double balance) {
        super(id, balance);
        this.overdraft=10000;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    @Override
    public void pay(double money) {
        if (this.getBalance() >= money*this.getDiscountRate()) {
          double t  =this.getBalance()-money*this.getDiscountRate();
          this.setBalance(t);
          System.out.println("尊敬的VIP顾客："+getId()+",本次消费"+money+",打折后消费"+ money*this.getDiscountRate()+",余额为："+getBalance());
        }else {
            double temp=overdraft+this.getBalance();
            if(temp>=money*this.getDiscountRate()){
                double t=money*this.getDiscountRate()-this.getBalance();
                this.setBalance(0);
                setOverdraft(this.overdraft-t);
                System.out.println("尊敬的VIP顾客"+getId() +",本次消费"+money+",你的余额不足,启用透支额"+t+",存款余额为零，透支额度剩余"+this.getOverdraft());
            }else {
                System.out.println("尊敬的VIP顾客" + getId() + ",你的余额不足，透支额也不足，请充值吧!");
            }

        }
    }

    public static void main(String[] args) {
        VIP vip = new VIP(2, 60000);
        vip.pay(58000);
        vip.pay(20000);
        vip.pay(10000);
    }
}
